from rest_framework import serializers
from cars.models import Car, MthCar


class CarLstSerl(serializers.ModelSerializer):
    STATUS_CHOISE = (
        (0, "新创建"),
        (1, "申请中"),
        (2, "待入场"),
        (3, "已入场"),
        (4, "已出场"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )

    class Meta:
        model = Car
        fields = (
            "id",
            "plate",
            "status",
            "status_text",
        )


class CarDetSerl(serializers.ModelSerializer):
    STATUS_CHOISE = (
        (0, "新创建"),
        (1, "申请中"),
        (2, "待入场"),
        (3, "已入场"),
        (4, "已出场"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    updated = serializers.DateTimeField(
        format="%Y-%m-%d %H:%M:%S", required=False, read_only=True
    )

    class Meta:
        model = Car
        exclude = ("created",)




class MthCarSerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)

    class Meta:
        model = MthCar
        exclude = ("created",)